import { AddressItem } from "@/types/global";
import { defineStore } from "pinia";
import { computed, ref } from "vue";

// 收货地址store
export const useAddressStore = defineStore('address', () => {
    // 选中的收货地址
    const selectedAddress = ref<AddressItem>();

    // 选中的收货地址描述
    const selectedAddressText = computed(() => selectedAddress.value ? `${selectedAddress.value.receiver} ${selectedAddress.value.fullLocation}` : void 0);

    // 修改选中地址
    const setSelectedAddress = (address?: AddressItem) => {
        if (address) selectedAddress.value = address;
    }

    return { selectedAddress, selectedAddressText, setSelectedAddress };
});